package com.moreemrecife.dao;

import com.moreemrecife.jpa.EntityManagerHelper;
import com.moreemrecife.jpa.Function;
import com.moreemrecife.jpa.User;

/**
 * Acesso ao banco de dados.
 */
public class AccessControlDao {

	/**
	 * Retrieve a User profile
	 * @param login
	 * @return
	 */
	public static User selectUser(String login) {

		return (User) EntityManagerHelper.get()
				.createQuery("Select u from User u WHERE u.login = :login")
				.setParameter("login", login).getSingleResult();
	}
	
	/**
	 * Persist data
	 * @param data
	 * @return
	 */
	public static int saveFunction(Function data) {
	    EntityManagerHelper.get().persist(data);
	    return data.getId();
	}
}
